<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form" enctype="multipart/form-data">
        <fieldset>
            <input type="hidden" id="userId" name="userId"/>
                      <div class="form-group">
                       <label class="col-md-2 control-label">昵称:</label>
                       <div class="col-md-5">
                        <input class="form-control" placeholder="昵称" type="text" name="username" id="username" onchange="updatename()" data-bv-notempty="true" data-bv-notempty-message="昵称不能为空" />
                       </div>
                      </div>
                      <div class="form-group">
                       <label class="col-md-2 control-label">手机号码:</label>
                       <div class="col-md-5">
                        <input class="form-control" placeholder="手机号码" type="text" name="phone" id="phone" data-bv-notempty="true" data-bv-notempty-message="手机号码不能为空" />
                       </div>
                      </div>

                      <div class="form-group">
                                 <label class="col-md-2 control-label">邮箱:</label>
                                 <div class="col-md-5">
                                  <input class="form-control" placeholder="邮箱" type="text" name="email" id="email"  />
                                 </div>
                                </div>

                      <div class="form-group">
                                <label class="col-md-2 control-label">头像:</label>
                                <div class="col-md-10">
                                <img id="icon" />
                                <input type="file" name="icon" id="icon" />
                                </div>
                                </div>
                       <div class="form-group">
                                      <label class="col-md-2 control-label">性别:</label>
                                      <div class="col-md-10" style="width: 120px">
                                       <select class="form-control input-sm" name="sex" id="sex">
                                       <option value="0" selected="selected">男</option>
                                       <option value="1" >女</option> </select>
                                  </div>
                                  </div>
                      <div class="form-group">
                                           <label class="col-md-2 control-label">生日:</label>
                                           <div class="col-md-5">
                                            <input class="form-control" placeholder="生日" type="text" name="birthday" id="birthday" onfocus="showDate()"/>
                                           </div>
                                          </div>
                        <div class="form-group">
                                                 <label class="col-md-2 control-label">证件类型:</label>
                                                 <div class="col-md-10" style="width: 120px">
                                                  <select class="form-control input-sm" name="identityType" id="identityType">
                                                  <option value="0" selected="selected">身份证</option>
                                                  <option value="2" >护照</option> </select>
                                             </div>
                                             </div>
                       <div class="form-group">
                                           <label class="col-md-2 control-label">证件号:</label>
                                           <div class="col-md-5">
                                            <input class="form-control" placeholder="证件号" type="text" name="idCardNo" id="idCardNo"  />
                                           </div>
                                          </div>
                        <div class="form-group">
                                                 <label class="col-md-2 control-label">实名认证:</label>
                                                 <div class="col-md-10" style="width: 120px">
                                                  <select class="form-control input-sm" name="isAttestation" id="isAttestation">
                                                  <option value="0" selected="selected">是</option>
                                                  <option value="2" >否</option> </select>
                                             </div>
                                             </div>
                        <div class="form-group">
                                                   <label class="col-md-2 control-label">会员等级:</label>
                                                   <div class="col-md-10" style="width: 120px">
                                                   <select class="form-control input-sm" name="level" id="level">
                                                   <option value="0" selected="selected">普通会员</option>
                                                   <option value="1" >导师</option>
                                                   <option value="2" >讲师</option>
                                                   <option value="3" >经理</option> </select>
                                                   </div>
                                                   </div>
                        <div class="form-group">
                                              <label class="col-md-2 control-label">邀请人:</label>
                                              <div class="col-md-5">
                                               <input class="form-control" placeholder="邀请人" type="text" name="inviter" id="inviter"  />
                                              </div>
                                             </div>
                        <div class="form-group">
                                            <label class="col-md-2 control-label">注册来源:</label>
                                            <div class="col-md-5">
                                             <input class="form-control" placeholder="注册来源" type="text" name="registSource" id="registSource"  />
                                            </div>
                                           </div>
                         <div class="form-group">
                                             <label class="col-md-2 control-label">身份证正面:</label>
                                             <div class="col-md-10">
                                             <img id="CardFront" />
                                             <input type="file" name="CardFront" id="CardFront" />
                                             </div>
                                             </div>
                         <div class="form-group">
                                             <label class="col-md-2 control-label">身份证反面:</label>
                                             <div class="col-md-10">
                                             <img id="CardBack" />
                                             <input type="file" name="CardBack" id="CardBack" />
                                             </div>
                                             </div>
                         <div class="form-group">
                                             <label class="col-md-2 control-label">手持身份证:</label>
                                             <div class="col-md-10">
                                             <img id="CardHand" />
                                             <input type="file" name="CardHand" id="CardHand" />
                                             </div>
                                             </div>
                         <div class="form-group">
                                              <label class="col-md-2 control-label">邀请二维码:</label>
                                              <div class="col-md-10">
                                              <img id="code" />
                                              </div>
                                              </div>
                            <div class="form-group">
                                            <label class="col-md-2 control-label">角色</label>
                                            <div class="checkbox" id="roles">
                                            </div>
                                        </div>

            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='userList.html'">返回</button>
                        <button class="btn btn-primary" id="btn" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>
<script type="text/javascript" src="../../global/js/my/roles/role.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript">

    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#birthday'
        });
    });
    initRoles();

    initData();

    function initData() {
        var id = getUrlParam("id");
        if (id != "") {
            $.ajax({
                type: 'get',
                url: '/clyjUser/' + id,
                async: false,
                success: function (result) {
                    var data = result.data;
                    $("#userId").val(data.userId);
                                        $("#username").val(data.username);
                                        $("#phone").val(data.phone);
                                        $("#email").val(data.email);
                                        $("#icon").attr("src",data.photo);
                                        $("#sex").val(data.sex);
                                        $("#birthday").val(data.birthday);
                                        $("#identityType").val(data.identityType);
                                        $("#idCardNo").val(data.idCardNo);
                                        $("#isAttestation").val(data.isAttestation);
                                        $("#level").val(data.level);
                                        $("#inviter").val(data.inviter);
                                        $("#registSource").val(data.registSource);
                                        $("#CardFront").attr("src",data.idCardFront);
                                        $("#CardBack").attr("src",data.idCardBack);
                                        $("#CardHand").attr("src",data.idCardHand);
                                        $("#code").attr("src",data.code);
                }
            });

            initRoleDatas(id);
        }
    }
 $('#form').bootstrapValidator();

    function update() {
        // 表单验证
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }

       /* var formdata = $("#form").serializeObject(  );
        formdata.roleId = getCheckedRoleIds();*/

        $("form").ajaxSubmit({
            type: 'post',
            url: '/clyjUser/updateUser',
            traditional: true,
            contentType: "application/json; charset=utf-8",
            //data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                    location.href = "userList.html";
                });
            }
        });
    }
function updatename() {
   var  s= $("#username").val();
          $.ajax({
            data:{
                    username:s,
                        },
                        dataType: 'json',
                        type: 'post',
              url: '/clyjUser/updatename',

              async:true,
              success: function (date) {
if(date){
layer.open({
  title: '提示'
  ,content: '该昵称已存在'
});
 $("#btn").attr("disabled","disabled");
}else {
layer.open({
  title: '提示'
  ,content: '该昵称可以使用'
});
    $("#btn").removeAttr("disabled","disabled");
}
              }
          });
}

</script>
</body>
</html>